package com.crm.system.controller.customerManager;

import cn.hutool.core.map.MapUtil;
import cn.hutool.http.Header;
import cn.hutool.http.HttpException;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.crm.common.model.DataResponse;
import com.crm.common.model.DhPageInfo;
import com.crm.common.model.DhResponse;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.common.util.CommonUtils;
import com.crm.model.entity.cluePoolManager.ClueVisitRecord;
import com.crm.model.entity.contactManager.Contact;
import com.crm.model.entity.contractManager.CustomerContract;
import com.crm.model.entity.customerManager.*;
import com.crm.model.entity.finishOrderProduct.FinishOrderProduct;
import com.crm.model.entity.orderManager.CustomerProductOrder;
import com.crm.model.entity.sys.UserAccount;
import com.crm.model.qo.customerManager.*;
import com.crm.model.vo.cluePoolManager.ClueFollowVO;
import com.crm.model.vo.contactManager.ContactMyVO;
import com.crm.model.vo.contactManager.IndustryAreaVO;
import com.crm.model.vo.customerContractManager.CustomerContractVO;
import com.crm.model.vo.customerContractManager.exchangeVO;
import com.crm.model.vo.customerManager.*;
import com.crm.model.vo.finishOrderProduct.FinishOrderProductVO;
import com.crm.model.vo.opportunityManager.OpportunityCustomerVO;
import com.crm.model.vo.orderManager.CustomerProductOrderVO;
import com.crm.model.vo.returnMoney.CustFinanceProductOderVO;
import com.crm.redis.service.customerManager.CustomerRedisService;
import com.crm.service.customerManager.CustomerTagDbService;
import com.crm.system.service.contactManager.ContactService;
import com.crm.system.service.customerManager.CustomerContactPersonService;
import com.crm.system.service.customerManager.CustomerService;
import com.crm.system.service.orderManager.CustomerProductOrderService;
import com.crm.system.service.returnMoney.ReturnMoneyService;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @ Author ：pym
 * @ Date   ：2021/1/18 15:53
 */
@RestController
@RequestMapping("/customerController")
@Slf4j
public class CustomerController {
    @Value("${esurl}")
    public String ESurl;

    @Autowired
    CustomerService customerService;

    @Autowired
    CustomerContactPersonService customerContactPersonService;

    @Autowired
    CustomerRedisService customerRedisService;

    @Autowired
    ContactService contactService;

    @Autowired
    CustomerProductOrderService customerProductOrderService;

    @Autowired
    ReturnMoneyService returnMoneyService;

    @Autowired
    CustomerTagDbService customerTagDbService;
    /**
     * 管理模块 -- 客户列表
     *
     * @return
     */
    @PostMapping("/customerList")
    public DataResponse customerPoolList(HttpServletRequest request,
                                         @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                         @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                         @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                         @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                         CustomerQO customerQO//查询条件
    ) {
        try {
            DhPageInfo<CustomerVO> customerVOList = customerService.selectCustomerVOList(pageIndex, pageSize, customerQO, sortName, sortOrder);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), customerVOList);
        } catch (Exception e) {
            log.error("customerController customerList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 俺的客户列表
     *
     * @param request
     * @param pageIndex
     * @param pageSize
     * @param sortName
     * @param sortOrder
     * @param customerQO
     * @return
     */
    @PostMapping("/meCustomerList")
    public DataResponse meCustomerList(HttpServletRequest request,
                                       @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                       @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                       @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                       @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                       CustomerQO customerQO//查询条件
    ) {
        try {
            DhPageInfo<CustomerVO> customerVOList = customerService.meCustomerList(pageIndex, pageSize, customerQO, sortName, sortOrder);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), customerVOList);
        } catch (Exception e) {
            log.error("customerController meCustomerList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 客户转入搜索客户
     *
     * @return
     */
    @GetMapping("/selectCustomerPreciseSearch")
    public DataResponse selectCustomerByCustomerNumberOrName(HttpServletRequest request,
                                                             @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                                             @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                                             @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                                             @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                                             CustomerQO customerQO//查询条件
    ) {
        try {
            DhPageInfo<CustomerVO> customerVOList = customerService.selectCustomerPreciseSearch(pageIndex, pageSize, customerQO, sortName, sortOrder);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), customerVOList);
        } catch (Exception e) {
            log.error("customerController selectCustomerPreciseSearch error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 修改客户编码
     *
     * @return
     */
    @PostMapping("/updateCustomerNumber")
    public DataResponse updateCustomerNumber(@RequestParam String customerId) {
        try {
            customerService.updateCustomerNumber(customerId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
        } catch (Exception e) {
            log.error("customerController updateCustomerNumber error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 修改意向客户 0无 1有
     *
     * @return
     */
    @PostMapping("/updatePotentialCustomerByZero")
    public DataResponse updatePotentialCustomerByZero(@RequestParam String customerId) {
        try {
            customerService.updatePotentialCustomer(customerId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
        } catch (Exception e) {
            log.error("customerController updateCustomerNumber error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 修改意向客户 0无 1有
     *
     * @return
     */
    @PostMapping("/updatePotentialCustomerByOne")
    public DataResponse updatePotentialCustomerByOne(@RequestParam String customerId) {
        try {
            customerService.updatePotentialCustomerOne(customerId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
        } catch (Exception e) {
            log.error("customerController updateCustomerNumber error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }


    /**
     * 客户--删除
     *
     * @param customerId
     * @return
     */
    @PostMapping("/deleteCustomer")
    public DataResponse deleteCustomer(@RequestParam(value = "customerId", required = true) String customerId) {
        try {
            Boolean result = customerService.deleteCustomerById(customerId);
            if (result) {
                Customer esVo = customerService.selectCustomerById(customerId);
                syncES(esVo, esVo.getAccountId(), "删除客户");
                return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
            }
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        } catch (Exception e) {
            log.error("customerController deleteCustomer error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    private void syncES(Customer customer, String accountId, String msg) {

        String token = getToken(accountId, msg);

        Map<String, Object> parMap = transBean2Map(customer);
        parMap.put("authorization", token);
        parMap.put("key", accountId);
        try {
            String result = HttpUtil.post(ESurl + "/cutomer/insertOrUpdate", parMap);
            log.info(result);
        } catch (HttpException e) {
            log.info(msg + "ES同步失败");
        }
    }

    private String getToken(String accountId, String msg) {
        Map<String, Object> tokenMap = new HashMap<>();
        tokenMap.put("accountId", accountId);
        try {
            return HttpUtil.post(ESurl + "/token/initToken", tokenMap);
        } catch (Exception e) {
            log.info(msg + "获取token失败");
        }
        return null;
    }


    /**
     * 对象装换map
     *
     * @param obj
     * @return
     */
    private static Map<String, Object> transBean2Map(Object obj) {
        if (obj == null) {
            return null;
        }
        Map<String, Object> map = new HashMap<>();
        try {
            BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
            PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
            for (PropertyDescriptor property : propertyDescriptors) {
                String key = property.getName();
                // 得到property对应的getter方法
                Method getter = property.getReadMethod();
                Object value = getter.invoke(obj);
                map.put(key, value);

            }
        } catch (Exception e) {
            System.out.println("transBean2Map Error " + e);
        }
        return map;
    }

    /**
     * 客户--收回
     *
     * @param customerId
     * @param returnReason
     * @return
     */
    @PostMapping("/retrieveCustomer")
    public DataResponse retrieveCustomer(@RequestParam(value = "customerId", required = true) String customerId,
                                         @RequestParam(value = "returnReason", required = true) String returnReason) {
        try {
            if (!StringUtils.isBlank(customerId)) {
                String result = customerService.retrieveCustomer(customerId, returnReason);
                if ("CL0001".equals(result)) {//客户已锁定
                    return new DhResponse(ResponseCodeEnum.CUSTOMER_LOCKED.getResponseCode());
                }
                if ("C00000".equals(result)) {//收回成功
                    Customer esVo = customerService.selectCustomerById(customerId);
                    syncES(esVo, esVo.getAccountId(), "管理端-客户公海-查看-收回");
                    return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
                }
                return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
            }
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        } catch (Exception e) {
            log.error("customerController retrieveCustomer error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    /**
     * 用户模块 -- 我的企业客户列表
     *
     * @param request
     * @param pageIndex
     * @param pageSize
     * @param sortName
     * @param sortOrder
     * @param customerQO
     * @return
     */
    @PostMapping("/userCustomerList")
    public DataResponse userCustomerPoolList(HttpServletRequest request,
                                             @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                             @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                             @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                             @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                             CustomerQO customerQO//查询条件
    ) {
        try {
            DhPageInfo<CustomerVO> customerVOList = customerService.selectMyCustomerList(pageIndex, pageSize, customerQO, sortName, sortOrder);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), customerVOList);
        } catch (Exception e) {
            log.error("customerController userCustomerList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 客户详情-修改公司简介
     *
     * @param customerCompanyInfo 公司类实体
     * @return
     */
    @PostMapping("/updateCustomerCompanyInfo")
    public DataResponse updateCustomerCompanyInfo(@RequestBody CustomerCompanyInfo customerCompanyInfo) {
        Boolean result = customerService.updateCustomerCompanyInfo(customerCompanyInfo);
        if (result) {
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
        } else {
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    /**
     * 客户详情-新增联系人-名字重复问题
     *
     * @param customerId         客户id
     * @param contactName        联系人姓名
     * @param contactInformation 联系方式
     * @return
     */
    @PostMapping("/getCustomerIdAndContactName")
    public DataResponse getCustomerIdAndContactName(@RequestParam(value = "customerId", required = true) String customerId,
                                                    @RequestParam(value = "contactName", required = true) String contactName,
                                                    @RequestParam(value = "contactInformation", required = true) String contactInformation) {
        try {
            CustomerContactPerson customerContactPerson = customerService.getCustomerIdAndContactName(customerId, contactName, contactInformation);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), customerContactPerson);
        } catch (Exception e) {
            log.error("customerController getCustomerIdAndContactName error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 竞品记录列表
     *
     * @param pageIndex  页码
     * @param pageSize   分页大小
     * @param sortName   排序列名字
     * @param sortOrder  排序规则(asc/desc)
     * @param customerId 客户id
     * @return
     */
    @PostMapping("/competitorList")
    public DataResponse competitorList(HttpServletRequest request,
                                       @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                       @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                       @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                       @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                       @RequestParam(value = "customerId", required = false) String customerId
    ) {
        try {
            DhPageInfo<Competitor> list = customerService.competitorList(pageIndex, pageSize, sortName, sortOrder, customerId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("customerController competitorList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 新增竞品
     *
     * @param competitor 竞品实体类
     * @return
     */
    @PostMapping("/addCompetitor")
    public DataResponse addCompetitor(@RequestBody Competitor competitor) {
        Boolean result = customerService.addCompetitor(competitor);
        if (result) {
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
        } else {
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    /**
     * 联系人模块 --通过登录人查询客户列表
     *
     * @return
     */
    @PostMapping("/getCustomerList")
    public DataResponse getCustomerList() {
        try {
            List<Customer> list = customerService.getCustomerList();
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("customerController getCustomerList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 获取内训下的客户
     *
     * @return
     */
    @PostMapping("/getCustomerUserList")
    public DataResponse getCustomerUserList() {
        List<CustomerVO> list = customerService.getCustomerUserList();
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
    }

    /***
     * @Description:新建合同-会员单次 通过登录人查询会员客户列表
     * @Param:
     * @Author: luojie
     * @Date: 2021/8/11 15:27
     */
    @PostMapping("/getMemberCustomerList")
    public DataResponse getMemberCustomerList() {
        try {
            List<Customer> list = customerService.getMemberCustomerList();
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("customerController getCustomerList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /***
     * @Description:查询非会员合同客户列表
     * @Author: luojie
     * @Date: 2021/4/23 15:04
     */
    @PostMapping("/getNonMemberContractCustomerList")
    public DataResponse getNonMemberContractCustomerList() {
        try {
            List<HashMap> list = customerService.getNonMemberContractCustomerList();
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("customerController getCustomerList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 通过当前登录人的公司查客户
     *
     * @return
     */
    @PostMapping("/getCustomerListByComp")
    public DataResponse getCustomerListByComp() {
        try {
            List<Customer> list = customerService.getCustomerListByComp();
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("customerController getCustomerListByComp error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 客户退回记录列表
     *
     * @param pageIndex 页码
     * @param pageSize  分页大小
     * @param sortName  排序列名字
     * @param sortOrder 排序规则(asc/desc)
     * @return
     */
    @PostMapping("/customerReturnList")
    public DataResponse customerReturnList(HttpServletRequest request,
                                           @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                           @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                           @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                           @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                           @RequestParam(value = "customerId", required = false) String customerId
    ) {
        try {
            DhPageInfo<CustomerReturnVO> list = customerService.customerReturnList(pageIndex, pageSize, sortName, sortOrder, customerId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("customerController customerReturnList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 客户领取记录列表
     *
     * @param request
     * @param pageIndex
     * @param pageSize
     * @param sortName
     * @param sortOrder
     * @return
     */
    @PostMapping("/customerReceiveList")
    public DataResponse customerReceiveList(HttpServletRequest request,
                                            @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                            @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                            @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                            @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                            @RequestParam(value = "customerId", required = false) String customerId
    ) {
        try {
            DhPageInfo<CustomerReceiveVO> list = customerService.customerReceiveList(pageIndex, pageSize, sortName, sortOrder, customerId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("customerController customerReceiveList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 客户详情商机管理
     *
     * @param pageIndex 页码
     * @param pageSize  分页大小
     * @param sortName  排序列名字
     * @param sortOrder 排序规则(asc/desc)
     * @return
     */
    @PostMapping("/opportunityByCustomerIdList")
    public DataResponse opportunityList(HttpServletRequest request,
                                        @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                        @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                        @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                        @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                        @RequestParam(value = "customerId", required = false) String customerId
    ) {
        try {
            DhPageInfo<OpportunityCustomerVO> list = customerService.opportunityByCustomerIdList(pageIndex, pageSize, sortName, sortOrder, customerId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("customerController opportunityList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 客户详情会员卡
     *
     * @param pageIndex 页码
     * @param pageSize  分页大小
     * @param sortName  排序列名字
     * @param sortOrder 排序规则(asc/desc)
     * @return
     */
    @PostMapping("/selectCardByCustomerIdList")
    public DataResponse selectCardByCustomerIdList(HttpServletRequest request,
                                                   @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                                   @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                                   @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                                   @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                                   @RequestParam(value = "customerId", required = false) String customerId
    ) {
        try {
            DhPageInfo<CardVO> list = customerService.selectCardByCustomerIdList(pageIndex, pageSize, sortName, sortOrder, customerId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("customerController selectCardByCustomerIdList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 客户详情税法直通车
     *
     * @param pageIndex 页码
     * @param pageSize  分页大小
     * @param sortName  排序列名字
     * @param sortOrder 排序规则(asc/desc)
     * @return
     */
    @PostMapping("/selectTaxCardByCustomerIdList")
    public DataResponse selectTaxCardByCustomerIdList(HttpServletRequest request,
                                                   @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                                   @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                                   @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                                   @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                                   @RequestParam(value = "customerId", required = false) String customerId
    ) {
        try {
            DhPageInfo<TaxCardVO> list = customerService.selectTaxCardByCustomerIdList(pageIndex, pageSize, sortName, sortOrder, customerId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("customerController selectCardByCustomerIdList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 客户公海-客户清单-领取
     *
     * @param customerId          客户id
     * @param customerPoolId      客户池id
     * @param nature              性质：1-全国公有池；2-分公司公有池；
     * @param affiliatedCompanyId 全国公有池关联公司id
     * @return
     */
    @PostMapping("/receiveCustomer")
    public DataResponse receiveCustomer(@RequestParam(value = "customerId", required = false) String customerId,
                                        @RequestParam(value = "customerPoolId", required = false) String customerPoolId,
                                        @RequestParam(value = "nature", required = false) String nature,
                                        @RequestParam(value = "affiliatedCompanyId", required = false) String affiliatedCompanyId) {
        try {
            if (!StringUtils.isBlank(customerId)) {
                String message = customerService.receiveCustomer(customerId, customerPoolId, nature, affiliatedCompanyId);
                Customer vo = customerService.selectCustomerById(customerId);
                syncES(vo, vo.getAccountId(), "客户公海-领取");
                return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), message);
            }
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        } catch (Exception e) {
            log.error("customerController receiveCustomer error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }


    /**
     * 客户公海-客户调转-领取
     *
     * @param customerId    客户id
     * @return
     */
    @PostMapping("/receiveCustomerAround")
    public DataResponse receiveCustomerAround(@RequestParam(value = "customerId", required = false) String customerId) {
        try {
            if (!StringUtils.isBlank(customerId)) {
                String message = customerService.receiveCustomerAround(customerId);
                return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), message);
            }
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        } catch (Exception e) {
            log.error("customerController receiveCustomerAround error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    /**
     * 客户调转-流转记录
     * @param pageIndex 页码
     * @param pageSize  条数
     * @param customerName  客户名称
     * @return
     */
    @PostMapping("/customerTransferRecordList")
    public DataResponse customerTransferRecordList(@RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                                   @RequestParam(value = "pageSize", required = true) Integer pageSize,
                                                   @RequestParam(value = "customerName",required = false) String customerName) {
        try {
            DhPageInfo<CustomerTransferRecordVo> voList = customerService.customerTransferRecordList(pageIndex, pageSize, customerName);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), voList);
        } catch (Exception e) {
            log.error("customerController customerTransferRecordList error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    /**
     * 新增客户
     *
     * @param request
     * @param customerAddQO
     * @return
     */
    @PostMapping("/addCustomer")
    public Map<String, String> addCustomer(HttpServletRequest request, @RequestBody CustomerAddQO customerAddQO) {
        Map<String, String> map = new HashMap<String, String>();
        try {
            map = customerService.addCustomer(customerAddQO);
            //return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),message);
            return map;
        } catch (Exception e) {
            log.error("customerController addCustomer error:", e);
            //return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
            map.put("code", "900000");
            map.put("customerId", "");
            return map;
        }
    }


    /**
     * 修改客户状态
     *
     * @param customerId
     * @param customerState
     * @return
     */
    @PostMapping("/updateCustomerState")
    public DataResponse updateCustomerState(@RequestParam(value = "customerId") String customerId,
                                            @RequestParam(value = "customerState") String customerState) {
        try {
            Boolean result = customerService.updateCustomerState(customerId, customerState);
            if (result) {
                return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
            }
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        } catch (Exception e) {
            log.error("customerController updateCustomerState error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }


    /**
     * 根据客户名称查重
     *
     * @param
     * @return
     * @author yuanyunfeng
     * @date 2021/4/19 11:21
     */
    @PostMapping("/findRepeatCustomerName")
    public DataResponse findRepeatByCustomerName(HttpServletRequest request, @RequestParam(value = "customerName") String customerName) {
//        if(StringUtils.isBlank(customerName)){
//            return new DhResponse(ResponseCodeEnum.PARAMETER_ERROR.getResponseCode());
//        }
        List<CustomerRepeatVO> repeatList = customerService.findRepeatByCustomerName(customerName);
        log.info("根据客户名称【{}】查询返回的重复记录有【{}】条", customerName, repeatList.size());
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), repeatList);
    }


    /**
     * 首页快速查重接口（根据客户名称/手机号查重）
     *
     * @param type         类型：1-按客户名称查重；2-按手机号查重
     * @param isVip        是否会员：A-全部，Y-会员，N-非会员
     * @param checkContent 内容
     * @return
     * @author yuanyunfeng
     * @date 2021/4/19 14:29
     */
    @GetMapping("/fastQueryRepeat")
    public DataResponse fastQueryRepeat(@RequestParam(value = "type") String type, @RequestParam(value = "isVip") String isVip, @RequestParam(value = "checkContent") String checkContent) {
//        log.info("进入首页快速查重的接口，接收的参数：type【{}】，isVip【{}】，checkContent【{}】", type, isVip, checkContent);
        if (StringUtils.isBlank(type) || StringUtils.isBlank(checkContent)) {
            return new DhResponse(ResponseCodeEnum.PARAMETER_ERROR.getResponseCode());
        }
        List<CustomerFQRepeatVO> fastRepeatList = customerService.fastQueryRepeat(type, isVip, checkContent);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), fastRepeatList);
    }


    /**
     * 用户-线索管理-我的线索池-线索清单-转化为客户
     *
     * @param clueId 线索id
     * @return
     */
    @PostMapping("/convertToCustomer")
    public DataResponse convertToCustomer(@RequestParam(value = "clueId") String clueId) {
        try {
            String result = customerService.convertToCustomer(clueId);
            if ("CF0001".equals(result)) {
                return new DhResponse(ResponseCodeEnum.CUSTOMER_PRESENCE.getResponseCode());
            }
            if ("CF0002".equals(result)) {
                return new DhResponse(ResponseCodeEnum.CUSTOMER_EXCEED.getResponseCode());
            }
            if ("CF0004".equals(result)) {
                return new DhResponse(ResponseCodeEnum.CUSTOMER_RELATION.getResponseCode());
            }
            if ("C00030".equals(result)) {
                return new DhResponse(ResponseCodeEnum.CLUE_QCC_CHECK.getResponseCode());
            }
            if ("success".equals(result)) {
                return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
            }
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        } catch (Exception e) {
            log.error("customerController convertToCustomer error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    /**
     * 客户详情跟进记录
     *
     * @param pageIndex 页码
     * @param pageSize  分页大小
     * @param sortName  排序列名字
     * @param sortOrder 排序规则(asc/desc)
     * @return
     */
    @PostMapping("/clueFollowList")
    public DataResponse clueFollowList(HttpServletRequest request,
                                       @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                       @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                       @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                       @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                       @RequestParam(value = "customerId", required = false) String customerId
    ) {
        try {
            DhPageInfo<ClueFollowVO> list = customerService.clueFollowList(pageIndex, pageSize, sortName, sortOrder, customerId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("customerController clueFollowList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 客户详情拜访记录
     *
     * @param pageIndex 页码
     * @param pageSize  分页大小
     * @param sortName  排序列名字
     * @param sortOrder 排序规则(asc/desc)
     * @return
     */
    @PostMapping("/visitRecordList")
    public DataResponse visitRecordList(HttpServletRequest request,
                                        @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                        @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                        @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                        @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                        @RequestParam(value = "customerId", required = false) String customerId
    ) {
        try {
            DhPageInfo<ClueVisitRecord> list = customerService.visitRecordList(pageIndex, pageSize, sortName, sortOrder, customerId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("customerController visitRecordList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 客户--分配
     *
     * @param distributeUserId ---被分配人员ID
     * @param customerId       ---客户ID
     * @param customerPoolId   ---客户池ID
     * @return
     */
    @PostMapping("/distributeCustomer")
    public DataResponse distributeCustomer(@RequestParam(value = "distributeUserId", required = true) String distributeUserId,
                                           @RequestParam(value = "customerId", required = true) String customerId,
                                           @RequestParam(value = "customerPoolId", required = true) String customerPoolId
    ) {
        try {
            Map<String, Object> result = customerService.distributeCustomer(distributeUserId, customerId, customerPoolId);
            if (result.containsKey("d000")) {//分配成功
                Customer vo = customerService.selectCustomerById(customerId);
                syncES(vo, vo.getAccountId(), "管理端-客户公海-查看-分配");
                return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), result);
            }
            if (result.containsKey("d001")) {//已分配的客户数达到最大值,不能进行分配
                return new DhResponse(ResponseCodeEnum.CUSTOMER_POOL_CAPACITY_EXCEEDED.getResponseCode(), result);
            }
            if (result.containsKey("d002")) {//客户已锁定
                return new DhResponse(ResponseCodeEnum.CUSTOMER_LOCKED.getResponseCode(), result);
            }
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
        } catch (Exception e) {
            log.error("customerController distributeCustomer error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    /**
     * 客户--释放
     *
     * @param customerId             客户Id
     * @param releaseReason          释放原因
     * @param membershipExpirationTm 会员到期时间
     * @return
     */
    @PostMapping("/releaseCustomer")
    public DataResponse releaseCustomer(@RequestParam(value = "customerId", required = true) String customerId,
                                        @RequestParam(value = "releaseReason", required = true) String releaseReason,
                                        @RequestParam(required = false) String membershipExpirationTm) {
        try {
            if (!StringUtils.isBlank(customerId)) {
                if (!StringUtils.isBlank(membershipExpirationTm)) {
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    // 设置lenient为false. 否则SimpleDateFormat会比较宽松地验证日期，比如2018-02-29会被接受，并转换成2018-03-01
                    sdf.setLenient(false);
                    if (sdf.parse(sdf.format(new Date())).getTime() <= sdf.parse(membershipExpirationTm).getTime()) {
                        return new DhResponse(ResponseCodeEnum.MEMBERSHIP_NOT_EXPIRED.getResponseCode());
                    }
                }
                Customer customer = customerService.selectCustomerById(customerId);
                Integer memberErrorData = customer.getMemberErrorData();
                if (memberErrorData == 2) {//客户已锁定
                    return new DhResponse(ResponseCodeEnum.CUSTOMER_LOCKED.getResponseCode());
                }
                Boolean result = customerService.releaseCustomer(customerId, releaseReason);
                if (result) {
                    Customer esVo = customerService.selectCustomerById(customerId);
                    syncES(esVo, esVo.getCreatePeopleId(), "我的客户--释放客户");
                    return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
                }
            }
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        } catch (Exception e) {
            log.error("customerController releaseCustomer error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    /**
     * 客户--查询是否是超级管理员
     *
     * @return
     */
    @PostMapping("/isAdmin")
    public DataResponse isAdmin() {
        try {
            UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();
            Boolean rs = CommonUtils.isAdmin(userAccount.getUserId());
            if (rs) {
                return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
            }
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        } catch (Exception e) {
            log.error("customerController isAdmin error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    /**
     * 客户详情产品明细
     *
     * @param pageIndex         页码
     * @param pageSize          分页大小
     * @param sortName          排序列名字
     * @param sortOrder         排序规则(asc/desc)
     * @param customerId        客户id
     * @param productCategories 产品分类 0:非会员;1:会员
     * @return
     */
    @PostMapping("/finishOrderProductList")
    public DataResponse finishOrderProductList(HttpServletRequest request,
                                               @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                               @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                               @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                               @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                               @RequestParam(value = "customerId", required = false) String customerId,
                                               @RequestParam(value = "productCategories", required = false) String productCategories
    ) {
        try {
            DhPageInfo<CustFinanceProductOderVO> list = customerService.finishOrderProductList(pageIndex, pageSize, sortName, sortOrder, customerId, productCategories);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("customerController visitRecordList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    @PostMapping("/selectFinishOrderProductList")
    public DataResponse selectFinishOrderProductList(HttpServletRequest request,
                                                     @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                                     @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                                     @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                                     @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                                     @RequestParam(value = "customerId", required = true) String customerId
    ) {
        try {
            DhPageInfo<FinishOrderProductVO> list = customerService.selectFinishOrderProductList(pageIndex, pageSize, sortName, sortOrder, customerId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            e.printStackTrace();
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }


    /**
     * 客户详情产品明细
     *
     * @param pageIndex  页码
     * @param pageSize   分页大小
     * @param sortName   排序列名字
     * @param sortOrder  排序规则(asc/desc)
     * @param customerId 客户id
     * @return
     */
    @PostMapping("/csdFinishOrderProductList")
    public DataResponse csdFinishOrderProductList(HttpServletRequest request,
                                                  @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                                  @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                                  @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                                  @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                                  @RequestParam(value = "customerId", required = false) String customerId
    ) {
        try {
            DhPageInfo<CustFinanceProductOderVO> list = customerService.csdFinishOrderProductList(pageIndex, pageSize, sortName, sortOrder, customerId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("customerController visitRecordList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }


    /**
     * 客户详情合同信息
     *
     * @param pageIndex  页码
     * @param pageSize   分页大小
     * @param sortName   排序列名字
     * @param sortOrder  排序规则(asc/desc)
     * @param customerId 客户id
     * @return
     */
    @PostMapping("/contractList")
    public DataResponse contractList(HttpServletRequest request,
                                     @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                     @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                     @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                     @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                     @RequestParam(value = "customerId", required = false) String customerId
    ) {
        try {
            DhPageInfo<CustomerContractVO> list = customerService.contractList(pageIndex, pageSize, sortName, sortOrder, customerId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("customerController contractList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 客户详情订单信息
     *
     * @param pageIndex  页码
     * @param pageSize   分页大小
     * @param sortName   排序列名字
     * @param sortOrder  排序规则(asc/desc)
     * @param customerId 客户id
     * @return
     */
    @PostMapping("/orderList")
    public DataResponse orderList(HttpServletRequest request,
                                  @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                  @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                  @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                  @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                  @RequestParam(value = "customerId", required = false) String customerId
    ) {
        try {
            DhPageInfo<CustomerProductOrder> list = customerService.orderList(pageIndex, pageSize, sortName, sortOrder, customerId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("customerController contractList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 客户分析
     *
     * @return
     */
    @PostMapping("/analyseCustomer")
    public DataResponse orderList(HttpServletRequest request,@RequestBody CustomerAnalysisRequestQo qo
    ) {
        try {
            AnalyseCustomerVO list = customerService.analyseCustomerByPeriod(qo.getStartDate(), qo.getEndDate(),false);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("customerController contractList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 客户分析
     *
     * @return
     */
    @PostMapping("/superAdminAnalyseCustomer")
    public DataResponse superAdminAnalyseCustomer(HttpServletRequest request,@RequestBody CustomerAnalysisRequestQo qo
    ) {
        try {
            AnalyseCustomerVO list = customerService.analyseCustomerByPeriod(qo.getStartDate(), qo.getEndDate(),true);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("customerController contractList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 客户详情订单信息
     *
     * @param pageIndex      页码
     * @param pageSize       分页大小
     * @param sortName       排序列名字
     * @param sortOrder      排序规则(asc/desc)
     * @param moveCustomerQO 筛选条件
     * @return
     * @Author renshaorong
     * @Date 2021/4/9
     */
    @PostMapping("getCustomerListByUserAccountId")
    public DataResponse getCustomerListByUserAccountId(HttpServletRequest request,
                                                       @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                                       @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                                       @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                                       @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                                       MoveCustomerQO moveCustomerQO) {
        DhPageInfo<CustomerVO> list = customerService.getCustomerListByUserAccountId(pageIndex, pageSize, moveCustomerQO, sortName, sortOrder);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
    }

    /**
     * 批量移动客户给指定用户
     *
     * @param customerList 被选中客户List
     * @return
     * @Author renshaorong
     * @Date 2021/4/9
     */
    @PostMapping("/moveSelectedCustomers")
//    public DataResponse moveSelectedCustomers(@RequestBody List<Customer> customerList,@RequestParam(value = "toUserAccountId", required = true) String toUserAccountId){
    public DataResponse moveSelectedCustomers(@RequestBody List<Customer> customerList) {
        return new DhResponse(customerService.moveSelectedCustomers(customerList));
    }

    /**
     * 查询客户下客户联系人
     *
     * @param customerId
     * @return {@link {com.crm.common.model.DataResponse}}
     * @Author pym
     * @Date 2021/4/14 15:46
     */
    @GetMapping("/selectCustomerContactPersons")
    public DataResponse selectCustomerContactPersons(@RequestParam(value = "customerId") String customerId) {
        try {
            List<CustomerContactPerson> customerContactPeople = customerContactPersonService.selectCustomerContactPersonList(customerId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), JSONObject.toJSON(customerContactPeople));
        } catch (Exception e) {
            log.error("customerController selectCustomerContactPersons error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    /**
     * 给redis存客户分析数据 （暂时测试用）
     *
     * @param accountId
     * @Author chaifuyou
     * @Date 2021/4/15 09:30
     */
    @GetMapping("/addAnalyseCustomer")
    public DataResponse addAnalyseCustomerToRedis(@RequestParam(value = "accountId") String accountId, AnalyseCustomerRedisVO vo) {
        try {
            String jsonDate = null;
            if (null != vo) {
                jsonDate = JSONObject.toJSONString(vo);
            }
            customerRedisService.addAnalyseCustomerToRedis(accountId, jsonDate);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
        } catch (Exception e) {
            log.error("customerController selectCustomerContactPersons error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    /**
     * 客户意向分析
     *
     * @param dateType 数据时间类型
     * @Author chaifuyou
     * @Date 2021/4/15 09:35
     */
    @GetMapping("/getAnalyseCustomerIntention")
    public DataResponse getAnalyseCustomerIntention(@RequestParam String dateType) {
        try {
            AnalyseCustomerRedisVO vo = customerService.getAnalyseCustomerIntention(dateType);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), vo);
        } catch (Exception e) {
            log.error("customerController selectCustomerContactPersons error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    /**
     * 根据客户ID查询联系人
     *
     * @param customerId -客户ID
     * @return {@link {com.crm.common.model.DataResponse}}
     * @Author pym
     * @Date 2021/4/15 14:16
     */
    @GetMapping("/selectContacts")
    public DataResponse selectCustomerContacts(@RequestParam(value = "customerId") String customerId) {
        try {
            List<ContactMyVO> contacts = contactService.selectCustomerContacts(customerId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), JSONObject.toJSON(contacts));
        } catch (Exception e) {
            log.error("customerController selectCustomerContactPersons error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    /***
     * @Description:根据公司id、联系人id、还有用户自己
     * @Param:
     * @Author: luojie
     * @Date: 2021/6/28 14:30
     */
    @GetMapping("/selectMyContacts")
    public DataResponse selectMyContacts(@RequestParam(value = "contactId") String contactId) {
        try {
            List<ContactMyVO> contacts = contactService.selectMyContactsByContactId(contactId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), JSONObject.toJSON(contacts));
        } catch (Exception e) {
            log.error("customerController selectCustomerContactPersons error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }


    /**
     * 新增个人客户
     *
     * @param request
     * @param customerAddQO -客户参数
     * @param file          -上传文件
     * @return {@link {com.crm.common.model.DataResponse}}
     * @Author pym
     * @Date 2021/4/19 16:51
     */
    @PostMapping("/addIndividualCustomer")
    public DataResponse addIndividualCustomer(HttpServletRequest request, CustomerAddQO customerAddQO,
                                              @RequestParam(value = "file", required = false) MultipartFile file) {
        try {
            String message = customerService.addIndividualCustomer(customerAddQO, file);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), message);
        } catch (Exception e) {
            log.error("customerController addIndividualCustomer error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    /**
     * 恢复被释放的客户
     *
     * @param userId
     * @param customerId
     * @Author chaifuyou
     * @Date 2021/4/23 15:21
     */
    @GetMapping("/recoverCustomer")
    public DataResponse recoverCustomer(@RequestParam(value = "userId", required = false) String userId,
                                        @RequestParam(value = "customerId", required = false) String customerId,
                                        @RequestParam(value = "customerReturnId", required = false) String customerReturnId) {
        try {
            boolean b = customerService.recoverCustomer(userId, customerId, customerReturnId);
            if (b) {
                return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
            }
            return new DhResponse(ResponseCodeEnum.RECOVER_CUSTOMER_PRESENCE.getResponseCode());
        } catch (Exception e) {
            log.error("customerController recoverCustomer error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    /**
     * 会员客户分析
     *
     * @param type
     * @Author chaifuyou
     * @Date 2021/4/27 8:21
     */
    @GetMapping("/vipCustomerAnalyse")
    public DataResponse vipCustomerAnalyse(Integer type) {
        try {
            VipCustomerAnalyseVO vo = customerService.vipCustomerAnalyse(type);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), vo);
        } catch (Exception e) {
            log.error("customerController vipCustomerAnalyse error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    /**
     * 会员分析-会员列表
     *
     * @return
     */
    @GetMapping("/selectVipCustomerList")
    public DataResponse selectVipCustomerList(HttpServletRequest request,
                                              @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                              @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                              @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                              @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                              Integer membershipLevel//会员等级
    ) {
        try {
            DhPageInfo<VipCustomerListVO> list = customerService.selectVipCustomerList(pageIndex, pageSize, membershipLevel, sortName, sortOrder);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("customerController selectVipCustomerList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 联系人列表跳转客户详情-查询是不是自己的客户
     *
     * @param customerId 客户id
     * @return
     */
    @PostMapping("/selectCustomerSelf")
    public DataResponse selectCustomerSelf(@RequestParam(value = "customerId", required = false) String customerId) {
        try {
            boolean result = customerService.selectCustomerSelf(customerId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), result);
        } catch (Exception e) {
            log.error("customerController selectCustomerSelf error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 新增商机-客户名称精准匹配
     *
     * @param customerName 客户名称
     * @return
     */
    @PostMapping("/selectCustomerNameReg")
    public DataResponse selectCustomerNameReg(@RequestParam(value = "customerName", required = false) String customerName) {
        try {
            boolean result = customerService.selectCustomerNameReg(customerName);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), result);
        } catch (Exception e) {
            log.error("customerController selectCustomerSelf error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 客户详情-修改客户评分
     *
     * @param customerId     客户id
     * @param customerRating 客户评分
     * @return
     */
    @PostMapping("/updateCustomerRating")
    public DataResponse updateCustomerRating(@RequestParam(value = "customerId", required = false) String customerId,
                                             @RequestParam(value = "customerRating", required = false) String customerRating) {
        Boolean result = customerService.updateCustomerRating(customerId, customerRating);
        if (result) {
            Customer esVo = customerService.selectCustomerById(customerId);
            syncES(esVo, esVo.getAccountId(), "客户详情-客户评分");
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
        } else {
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    /**
     * 客户管理 - 单品客户 - 新增单品客户列表
     *
     * @param request
     * @param pageIndex    页码
     * @param pageSize     分页大小
     * @param sortName     排序列名字
     * @param sortOrder    排序规则(asc/desc)
     * @param customerName 客户名称
     * @return {@link {com.crm.common.model.DataResponse}}
     * @Author pym
     * @Date 2021/4/30 10:46
     */
    @PostMapping("/selectSingleProductCustomerList")
    public DataResponse selectSingleProductCustomerList(HttpServletRequest request,
                                                        @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                                        @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                                        @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                                        @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                                        @RequestParam(value = "customerName", required = false) String customerName//客户名称
    ) {
        try {
            DhPageInfo<CustomerVO> customerVOList = customerService.selectSingleProductCustomerList(pageIndex, pageSize, customerName, sortName, sortOrder);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), customerVOList);
        } catch (Exception e) {
            log.error("customerController selectSingleProductCustomerList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 客户管理-客户详情-会员产品-详细信息
     *
     * @param request
     * @param customerId            客户Id
     * @param memberProductId       会员产品id
     * @param finishOrderProductNum 产品号
     * @param orderId               订单id
     * @param memberProductCode     产品编码
     * @param bs                    0会员 1非会员
     * @return
     */
    @PostMapping("/selectCustomerProductDetail")
    public DataResponse selectCustomerProductDetail(HttpServletRequest request,
                                                    @RequestParam(value = "customerId", required = false) String customerId,
                                                    @RequestParam(value = "memberProductId", required = false) String memberProductId,
                                                    @RequestParam(value = "finishOrderProductNum", required = false) String finishOrderProductNum,
                                                    @RequestParam(value = "orderId", required = false) String orderId,
                                                    @RequestParam(value = "memberProductCode", required = false) String memberProductCode,
                                                    @RequestParam(value = "bs", required = false) String bs
    ) {
        try {
            CustomerProductDetailMemberCardVO vo = customerService.selectCustomerProductDetail(customerId, memberProductId, finishOrderProductNum, orderId, memberProductCode, bs);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), vo);
        } catch (Exception e) {
            log.error("customerController selectCustomerProductDetail error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 客户管理-客户详情-会员产品-会员卡
     *
     * @param request
     * @param finishOrderProductNum 产品号
     * @param orderId               订单id
     * @return
     */
    @PostMapping("/selectCardList")
    public DataResponse selectCardList(HttpServletRequest request,
                                                    @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                                    @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                                    @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                                    @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                                    @RequestParam(value = "orderId", required = false) String orderId,
                                                    @RequestParam(value = "finishOrderProductNum", required = false) String finishOrderProductNum
    ) {
        try {
            DhPageInfo<CustomerProductDetailMemberCard> list = customerService.selectCardList(pageIndex,pageSize,sortName,sortOrder,orderId,finishOrderProductNum);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("customerController selectCardList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 客户管理-客户详情-会员产品-税法直通车
     *
     * @param request
     * @param finishOrderProductNum 产品号
     * @param orderId               订单id
     * @return
     */
    @PostMapping("/selectTrainTaxList")
    public DataResponse selectTrainTaxList(HttpServletRequest request,
                                       @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                       @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                       @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                       @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                       @RequestParam(value = "orderId", required = false) String orderId,
                                       @RequestParam(value = "finishOrderProductNum", required = false) String finishOrderProductNum
    ) {
        try {
            DhPageInfo<CustomerProductDetailThroughTrainTax> list = customerService.selectTrainTaxList(pageIndex,pageSize,sortName,sortOrder,orderId,finishOrderProductNum);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("customerController selectTrainTaxList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 客户管理-客户详情-会员产品-兑换码
     * @param finishOrderProductNum 产品号
     * @param orderId               订单id
     * @return
     */
    @PostMapping("/selectExchangeCodeList")
    public DataResponse selectExchangeCodeList(HttpServletRequest request,
                                           @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                           @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                           @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                           @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                           @RequestParam(value = "orderId", required = false) String orderId,
                                           @RequestParam(value = "finishOrderProductNum", required = false) String finishOrderProductNum
    ) {
        try {
            DhPageInfo<CustomerProductDetailExchangeCode> list = customerService.selectExchangeCodeList(pageIndex,pageSize,sortName,sortOrder,orderId,finishOrderProductNum);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("customerController selectExchangeCodeList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 客户管理-客户详情-会员产品-云顾问卡
     * @param finishOrderProductNum 产品号
     * @param orderId               订单id
     * @return
     */
    @PostMapping("/selectYunList")
    public DataResponse selectYunList(HttpServletRequest request,
                                               @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                               @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                               @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                               @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                               @RequestParam(value = "orderId", required = false) String orderId,
                                               @RequestParam(value = "finishOrderProductNum", required = false) String finishOrderProductNum
    ) {
        try {
            DhPageInfo<CustomerProductDetailYun> list = customerService.selectYunList(pageIndex,pageSize,sortName,sortOrder,orderId,finishOrderProductNum);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("customerController selectYunList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 客户管理-客户详情-会员产品-充值卡
     * @param finishOrderProductNum 产品号
     * @param orderId               订单id
     * @return
     */
    @PostMapping("/selectRechargeCodeList")
    public DataResponse selectRechargeCodeList(HttpServletRequest request,
                                      @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                      @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                      @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                      @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                      @RequestParam(value = "orderId", required = false) String orderId,
                                      @RequestParam(value = "finishOrderProductNum", required = false) String finishOrderProductNum
    ) {
        try {
            DhPageInfo<CustomerProductDetailRechargeCode> list = customerService.selectRechargeCodeList(pageIndex,pageSize,sortName,sortOrder,orderId,finishOrderProductNum);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("customerController selectRechargeCodeList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 客户管理-客户详情-会员产品-优惠劵
     * @param finishOrderProductNum 产品号
     * @param orderId               订单id
     * @return
     */
    @PostMapping("/selectCouponList")
    public DataResponse selectCouponList(HttpServletRequest request,
                                               @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                               @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                               @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                               @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                               @RequestParam(value = "orderId", required = false) String orderId,
                                               @RequestParam(value = "finishOrderProductNum", required = false) String finishOrderProductNum
    ) {
        try {
            DhPageInfo<CustomerProductDetailCoupon> list = customerService.selectCouponList(pageIndex,pageSize,sortName,sortOrder,orderId,finishOrderProductNum);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("customerController selectCouponList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }



    /**
     * 客户管理-客户详情-会员产品-课程-产品信息
     *
     * @param request
     * @param customerId 客户Id
     * @param courseNum  课程标号
     * @return
     */
    @PostMapping("/selectCustomerProduct")
    public DataResponse selectCustomerProduct(HttpServletRequest request,
                                              @RequestParam(value = "customerId", required = false) String customerId,
                                              @RequestParam(value = "courseNum", required = false) String courseNum
    ) {
        try {
            List<CustomerProductVO> list = customerService.selectCustomerProduct(customerId, courseNum);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("customerController selectCustomerProduct error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 我的客户-查询客户里面有的行业
     *
     * @param bs 0管理端 1用户端
     * @return
     */
    @PostMapping("/selectIndustry")
    public DataResponse selectIndustry(@RequestParam(value = "bs", required = true) String bs) {
        try {
            List<IndustryAreaVO> list = customerService.selectIndustry(bs, "industry");
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("customerController selectIndustry error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    /**
     * 我的客户-查询客户里面有的地区
     *
     * @param bs 0管理端 1用户端
     * @return
     */
    @PostMapping("/selectProvince")
    public DataResponse selectProvince(@RequestParam(value = "bs", required = true) String bs) {
        try {
            List<IndustryAreaVO> list = customerService.selectIndustry(bs, "province");
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("customerController selectIndustry error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }


    /**
     * 我的客户-查询客户里面的热门标签
     *
     * @param bs 0管理端 1用户端
     * @return
     */
    @PostMapping("/selectTag")
    public DataResponse selectTag(@RequestParam(value = "bs", required = true) String bs) {
        try {
            List<TagVO> list = customerService.selectTag(bs);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("customerController selectTag error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    /**
     * 我的客户-查询客户里面的热门标签
     *
     * @param bs 0管理端 1用户端
     * @return
     */
    @PostMapping("/selectTagAndCustomizeTag")
    public DataResponse selectTagAndCustomizeTag(@RequestParam(value = "bs", required = true) String bs) {
        try {
            HashMap<String,List<TagVO>> res = new HashMap<>();
            List<TagVO> list = customerService.selectTag(bs);
            List<TagVO> customer = new ArrayList<>();
            List<ChsCustomerTag> tags = customerTagDbService.selectCustomerList();
            tags.stream().forEach(chsCustomerTag -> {
                TagVO vo =new TagVO();
                vo.setTag(chsCustomerTag.getTag());
                customer.add(vo);
            });
            res.put("客户自定义标签",list);
            res.put("客户快捷标签",customer);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), res);
        } catch (Exception e) {
            log.error("customerController selectTag error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    /**
     * 我的客户-查询客户里面的跟进标签
     *
     * @param bs 0管理端 1用户端
     * @return
     */
    @PostMapping("/selectFollowTag")
    public DataResponse selectFollowTag(@RequestParam(value = "bs", required = true) String bs) {
        try {
            List<TagVO> list = customerService.selectFollowTag(bs);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("customerController selectTag error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    /**
     * 客户-客户订单完成的会员产品会员卡
     *
     * @param customerProductDetailMemberCard 客户订单完成的会员产品会员卡实体
     * @return
     */
    @PostMapping("/addCustomerProductDetailMemberCard")
    public DataResponse addCustomerProductDetailMemberCard(@RequestBody CustomerProductDetailMemberCard customerProductDetailMemberCard) {
        String result = customerService.addCustomerProductDetailMemberCard(customerProductDetailMemberCard);
        if ("MC001".equals(result)) {
            return new DhResponse(ResponseCodeEnum.NOT_MEMBER_CARD.getResponseCode());
        } else if ("ERROR".equals(result)) {
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        } else {
            CustomerProductDetailMemberCard memberCard = customerService.getCustomerProductDetailMemberCardById(result);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), memberCard);
        }
    }


    /**
     * @Description: 根据产品编码查询客户信息
     * @Param: [productCode]
     * @Return: com.crm.common.model.DataResponse
     * @Author: lixq-f
     * @Date: 2021/6/2
     **/
    @GetMapping("/selectCustomersByProductCode")
    public DataResponse selectCustomersByProductCode(@RequestParam("productCode") String productCode) {
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), customerService.selectCustomersByProductCode(productCode));
    }


    /**
     * @Description: 根据客户id获取客户下产品信息
     * @Param: [customerId]
     * @Return: java.util.List<com.crm.model.vo.returnMoney.ProductOfCustomerVO>
     * @Author: lixq-f
     * @Date: 2021/6/3
     **/
    @GetMapping("/selectProductsByCustomerId")
    public DataResponse selectProductsByCustomerId(@RequestParam("customerId") String customerId,
                                                   @RequestParam("productCode") String productCode) {
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), customerService.selectProductsByCustomerId(customerId, productCode));
    }

    /**
     * 修改客户信息
     *
     * @Author renshaorong
     * @Date 2021/7/12
     **/
    @PostMapping("/updateCustomer")
    public DataResponse updateCustomer(@RequestBody Customer customer) {
        return new DhResponse(customerService.updateCustomer(customer));
    }

    /**
     * 信息错误
     *
     * @return
     */
    @PostMapping("/infomationErrorList")
    public DataResponse infomationErrorList(HttpServletRequest request,
                                            @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                            @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                            @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                            @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                            CustomerQO customerQO//查询条件
    ) {
        DhPageInfo<CustomerVO> customerVOList = customerService.selectInfomationErrorList(pageIndex, pageSize, customerQO, sortName, sortOrder);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), customerVOList);
    }

    /**
     * 获取客户所在池性质：1-全国公有池；2-分公司公有池；
     *
     * @return
     */
    @PostMapping("/getPoolType")
    public DataResponse getPoolType(String customerId) {
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), customerService.getPoolType(customerId));
    }

    /**
     * 往Redis里批量添加客户信息
     *
     * @param
     * @return {@link {com.crm.common.model.DataResponse}}
     * @Author pym
     * @Date 2021/7/21 13:28
     */
    @PostMapping("/insertCustomerToRedis")
    public DataResponse insertCustomerToRedis() {
        try {
            customerService.insertCustomerToRedis();
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
        } catch (Exception e) {
            log.error("customerController insertCustomerToRedis error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 发码
     *
     * @return
     */
    @PostMapping("/hairpin")
    public DataResponse hairpin(HttpServletRequest request,
                                @RequestParam(value = "orderId", required = true) String orderId,
                                @RequestParam(value = "productCode", required = true) String productCode,
                                @RequestParam(value = "productQuantity", required = false) String productQuantity,
                                @RequestParam(value = "productFinalPrice", required = false) BigDecimal productFinalPrice,
                                @RequestParam(value = "finishOrderProductNum", required = false) String finishOrderProductNum,
                                @RequestParam(value = "isRepairHairpin", required = false) String isRepairHairpin
    ) {
        UserAccount user = (UserAccount) SecurityUtils.getSubject().getPrincipal();//获取登录人信息
        CustomerProductOrderVO orderDetailVO = customerProductOrderService.getOrderInfoById(orderId);
        String rs = returnMoneyService.reqCrm(orderDetailVO, productCode, productQuantity, productFinalPrice, user, finishOrderProductNum);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), rs);
    }

    /**
     * 补码
     *
     * @return
     */
    @PostMapping("/repairHairpin")
    public DataResponse repairHairpin(HttpServletRequest request,
                                @RequestParam(value = "orderId", required = true) String orderId,
                                @RequestParam(value = "productCode", required = true) String productCode,
                                @RequestParam(value = "productFinalPrice", required = false) BigDecimal productFinalPrice,
                                @RequestParam(value = "finishOrderProductNum", required = false) String finishOrderProductNum
    ) {
        UserAccount user = (UserAccount) SecurityUtils.getSubject().getPrincipal();//获取登录人信息
        CustomerProductOrderVO orderDetailVO = customerProductOrderService.getOrderInfoById(orderId);
        String rs = returnMoneyService.repairHairpin(orderDetailVO, productCode, productFinalPrice, user, finishOrderProductNum);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), rs);
    }

    /**
     * 客服管理-客户详情-会员卡信息
     *
     * @param request
     * @param customerId 客户Id
     * @return
     */
    @PostMapping("/selectCardByCustomerId")
    public DataResponse selectCustomerProductDetail(HttpServletRequest request,
                                                    @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                                    @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                                    @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                                    @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                                    @RequestParam(value = "customerId", required = false) String customerId,
                                                    @RequestParam(value = "cardNumber", required = false) String cardNumber
    ) {
        try {
            DhPageInfo<CustomerProductDetailMemberCard> vo = customerService.selectCardByCustomerId(customerId, cardNumber, pageIndex, pageSize, sortName, sortOrder);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), vo);
        } catch (Exception e) {
            log.error("customerController selectCardByCustomerId error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 查询客户下的产品
     *
     * @param request
     * @param customerId 客户Id
     * @return
     */
    @PostMapping("/selectProductByCustomerId")
    public DataResponse selectProductByCustomerId(HttpServletRequest request,
                                                  @RequestParam(value = "customerId", required = false) String customerId
    ) {
        try {
            List<CustFinanceProductOderVO> list = customerService.selectProductByCustomerId(customerId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("customerController selectProductByCustomerId error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 查询客户下的其他联系人
     *
     * @param request
     * @param customerId 客户Id
     * @return
     */
    @PostMapping("/selectOtherContactByCustomerId")
    public DataResponse selectOtherContactByCustomerId(HttpServletRequest request,
                                                       @RequestParam(value = "customerId", required = false) String customerId,
                                                       @RequestParam(value = "contactId", required = false) String contactId
    ) {
        try {
            List<Contact> vo = customerService.selectOtherContactByCustomerId(customerId, contactId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), vo);
        } catch (Exception e) {
            log.error("customerController selectOtherContactByCustomerId error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }


    /**
     * changeProductXcchHychGdb
     * 产品明细 --兑换
     *
     * @param vo
     * @return
     * @Author wangpeng
     * @Date 2021/10/27
     */
    @PostMapping("/updateProductXcchHychGdb")
    private DataResponse changeProductXcchHychGdb(exchangeVO vo) {
        try {
            Map map = customerService.changeProductXcchHychGdb(vo);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), map);
        } catch (Exception e) {
            e.printStackTrace();
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 用户端 - 客户公海 - 分公司 筛选列表
     * @Author pym
     * @Date  2021/11/23 11:22
     * @param pageIndex -页码
     * @param pageSize -分页大小
     * @return {@link {com.crm.common.model.DataResponse}}
     */
    @PostMapping("/selectCustomerPoolNameList")
    public DataResponse selectCustomerPoolNameList(@RequestParam(value = "pageIndex") Integer pageIndex,//页码
                                                   @RequestParam(value = "pageSize") Integer pageSize//分页大小
    ) {
        try {
            DhPageInfo<CustomerPoolNameVO> customerPoolNameVOList = customerService.selectCustomerPoolNameList(pageIndex, pageSize);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), customerPoolNameVOList);
        } catch (Exception e) {
            log.error("customerController selectCustomerPoolNameList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 用户端 - 客户公海 - 地区 筛选列表
     * @Author pym
     * @Date  2021/11/23 11:39
     * @param pageIndex -页码
     * @param pageSize -分页大小
     * @param customerPoolId -客户池Id
     * @return {@link {com.crm.common.model.DataResponse}}
     */
    @PostMapping("/selectProvinceNameList")
    public DataResponse selectProvinceNameList(@RequestParam(value = "pageIndex") Integer pageIndex,//页码
                                               @RequestParam(value = "pageSize") Integer pageSize,//分页大小
                                               @RequestParam(value = "customerPoolId", required = false) String customerPoolId
    ) {
        try {
            DhPageInfo<String> provinceNameList = customerService.selectProvinceNameList(pageIndex, pageSize, customerPoolId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), provinceNameList);
        } catch (Exception e) {
            log.error("customerController selectProvinceNameList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 用户端 - 客户公海 - 标签 筛选列表
     * @Author pym
     * @Date  2021/11/23 14:20
     * @param pageIndex -页码
     * @param pageSize -分页大小
     * @param customerPoolId -客户池Id
     * @return {@link {com.crm.common.model.DataResponse}}
     */
    @PostMapping("/selectTagList")
    public DataResponse selectTagList(@RequestParam(value = "pageIndex") Integer pageIndex,//页码
                                      @RequestParam(value = "pageSize") Integer pageSize,//分页大小
                                      @RequestParam(value = "customerPoolId", required = false) String customerPoolId
    ) {
        try {
            DhPageInfo<String> tagList = customerService.selectTagList(pageIndex, pageSize, customerPoolId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), tagList);
        } catch (Exception e) {
            log.error("customerController selectTagList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 用户端 - 客户公海 - 客户池下客户列表
     * @Author pym
     * @Date  2021/11/23 14:51
     * @param pageIndex -页码
     * @param pageSize -分页大小
     * @param sortName -排序列名字
     * @param sortOrder -排序规则(asc/desc)
     * @param poolCustomerQO -筛选条件
     * @return {@link {com.crm.common.model.DataResponse}}
     */
    @PostMapping("/selectPoolCustomerList")
    public DataResponse selectPoolCustomerList(@RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                               @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                               @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                               @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                               PoolCustomerQO poolCustomerQO//筛选条件
    ) {
        try {
            DhPageInfo<PoolCustomerVO> poolCustomerVOList = customerService.selectPoolCustomerList(pageIndex, pageSize, poolCustomerQO, sortName, sortOrder);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), poolCustomerVOList);
        } catch (Exception e) {
            log.error("customerController selectPoolCustomerList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 更新客户会员开始时间和结束时间
     */
    @PostMapping("/updateCustomerMemberDate")
    private DataResponse updateCustomerMemberDate() {
        try {
            customerService.updateCustomerMemberDate();
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
        } catch (Exception e) {
            e.printStackTrace();
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 修改合同状态  改为已结束
     */
    @PostMapping("/updateContractStatus")
    private DataResponse updateContractStatus() {
        try {
            customerService.updateContractStatus();
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
        } catch (Exception e) {
            e.printStackTrace();
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 用户端 - 客户公海 - 行业 筛选列表
     * @Author pym
     * @Date  2021/12/10 10:57
     * @param pageIndex -页码
     * @param pageSize -分页大小
     * @param customerPoolId -客户池Id
     * @return {@link {com.crm.common.model.DataResponse}}
     */
    @PostMapping("/selectIndustryList")
    public DataResponse selectIndustryList(@RequestParam(value = "pageIndex") Integer pageIndex,//页码
                                           @RequestParam(value = "pageSize") Integer pageSize,//分页大小
                                           @RequestParam(value = "customerPoolId", required = false) String customerPoolId
    ) {
        try {
            DhPageInfo<String> industryList = customerService.selectIndustryList(pageIndex, pageSize, customerPoolId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), industryList);
        } catch (Exception e) {
            log.error("customerController selectIndustryList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }


}
